<?php
include_once '../inc/config.inc.php';
include_once '../inc/mysqli.inc.php';
include_once '../inc/tool.inc.php';
//var_dump($_SERVER); exit();
if(!isset($_GET['id'])||!is_numeric($_GET['id'])){
    skip('childModule.php','error','id参数错误！ ');
}
$link=connect();
$query="select *from childModule where id={$_GET['id']}";
$result=execute($link,$query);
if(!mysqli_num_rows($result)){
    skip('childModule.php','error','该子版块不存在！');
}
$data=mysqli_fetch_assoc($result);
$data=dehtml($data);
if(isset($_POST['submit'])){
    //var_dump($data);var_dump($_POST); exit();
    $link=connect();
    $cheekflag='cm_update';
include_once 'inc/checkinfo.inc.php';
    $query="update childModule set referid={$_POST['referid']},moduleName='{$_POST['moduleName']}',info='{$_POST['info']}',memberid={$_POST['memberid']},sort={$_POST['sort']} where id={$_GET['id']}";
    $result=execute($link,$query);
    if(mysqli_affected_rows($link)){
        skip('childModule.php','ok','修改成功！');
    }elseif($data['moduleName']==$_POST['moduleName']&&$data['sort']==$_POST['sort']&&$data['referid']==$_POST['referid']&&$data['info']==$_POST['info']&&$data['memberid']==$_POST['memberid']){
        skip('childModule.php','attention','数据未作修改！');
    }
    else{
        skip("$_SERVER[REQUEST_URI]",'error','修改失败，请重试！ ');
    }
}

?>
<?php
$template='添加子板块';
include_once 'inc/header.inc.php';

?>
 <div id="main">
        <div class="intro"><?php echo $template." —— {$data['moduleName']}" ?></div>  
        <form method="post">   
            <table class="au"> 
                <tr>
                    <td>所属父板块</td>
                    <td>
                        <select name="referid">
                        <option value="0">=========请选择一个父板块=========</option>
                        <?php 
                            $query="select *from fatherModule";
                            $result=execute($link,$query);
                            while($dataf=mysqli_fetch_assoc($result)){
                                $dataf=dehtml($dataf);
                                if($data['referid']==$dataf['id']){
                                    echo "<option value='{$dataf['id']}' selected='selected'>{$dataf['moduleName']}</option>"; 
                                }else{
                                    echo "<option value='{$dataf['id']}'>{$dataf['moduleName']}</option>"; 
                                }
                               
                            }
                            mysqli_close($link);
                        ?>
                        </select>
                    </td>
                    <td><span>* 请选择一个父板块</span></td>
                </tr>
                <tr>
                    <td>子板块名称</td>
                    <td><input type="text" name="moduleName" value="<?php echo $data['moduleName'] ?>"></td>
                    <td><span>* 板块名称不得为空，最大不超过40个字符</span></td>
                </tr>
                <tr>
                    <td>&nbsp;&nbsp;板块简介</td>
                    <td><textarea name="info"><?php echo $data['info'] ?></textarea></td>
                    <td><span>内容最大不超过255个字符</span></td>
                </tr>
                <tr>
                    <td>&nbsp;&nbsp;版&nbsp;&nbsp;&nbsp;&nbsp;主&nbsp;&nbsp;</td>
                    <td>
                        <select name="memberid">
                        <option value="0">=======请选择一个会员作为版主=======</option>
                        </select>
                    </td>
                    <td><span>选择一个会员作为版主</span></td>
                </tr>
                <tr>
                    <td>&nbsp;&nbsp;&nbsp;&nbsp;排&nbsp;&nbsp;&nbsp;&nbsp;序</td>
                    <td><input type="text" value="<?php echo $data['sort'] ?>" name="sort" ></td>
                    <td><span>* 填写一个数字</span> </td>
                </tr>
            </table>
            <input type="submit" name="submit" value="修改" class="nsubmit" />
        </form>
    </div>

<?php
    include_once 'inc/footer.inc.php';
?>
